package com.asm.controller.api;

import com.asm.controller.BaseController;
import com.asm.dto.PageResult;
import com.asm.dto.Result;
import com.asm.service.CommunityService;
import com.asm.service.SpotService;
import com.asm.vo.sys.SpotReserveVo;
import com.asm.vo.sys.SpotVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiParam;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * @author ZhuangGuiMan
 */
@Api(value = "广告位Controller")
@RestController
public class SpotController extends BaseController {
    @Resource
    private SpotService spotService;

    /**
     * 分页查询所有广告位
     *
     * @param pageNumber 当前页码
     * @param pageSize   页面大小
     * @return 分页形式的广告位列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNumber", value = "当前页码"),
            @ApiImplicitParam(name = "pageSize", value = "页面大小")
    })
    @GetMapping("/spots")
    public ResponseEntity<PageResult<SpotVo>> getAllSpots(Integer pageNumber, Integer pageSize) {
        PageResult<SpotVo> list = spotService.findAllSpots(pageNumber, pageSize);
        return new ResponseEntity(new Result().ok("success", list), HttpStatus.OK);
    }

    /**
     * 根据Id获取广告位
     *
     * @param id 广告位编号
     * @return 广告位
     */
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "广告位编号")})
    @GetMapping("/spot/{id}")
    public ResponseEntity<Result<SpotVo>> getSpotById(@PathVariable("id") Long id) {
        return new ResponseEntity(new Result().ok("success", spotService.findSpotById(id)), HttpStatus.OK);
    }

    /**
     * 根据广告位类型分页查询广告位
     *
     * @param type       广告位类型
     * @param pageNumber 当前页码
     * @param pageSize   页面大小
     * @return 分页形式的广告位列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "广告位类型"),
            @ApiImplicitParam(name = "pageNumber", value = "当前页码"),
            @ApiImplicitParam(name = "pageSize", value = "页面大小")
    })
    @GetMapping("/spots/type/{type}")
    public ResponseEntity<PageResult<SpotVo>> getSpotsByType(@PathVariable("type") String type, Integer pageNumber, Integer pageSize) {
        return new ResponseEntity(new Result().ok("success", spotService.findSpotByType(type, pageNumber, pageSize)), HttpStatus.OK);
    }

    /**
     * 根据广告位大小分页查询广告位
     *
     * @param size       广告位大小
     * @param pageNumber 当前页码
     * @param pageSize   页面大小
     * @return 分页形式的广告位列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "size", value = "广告位大小"),
            @ApiImplicitParam(name = "pageNumber", value = "当前页码"),
            @ApiImplicitParam(name = "pageSize", value = "页面大小")
    })
    @GetMapping("/spots/size/{size}")
    public ResponseEntity<PageResult<SpotVo>> getSpotsBySize(@PathVariable("size") String size, Integer pageNumber, Integer pageSize) {
        return new ResponseEntity(new Result().ok("success", spotService.findSpotBySize(size, pageNumber, pageSize)), HttpStatus.OK);
    }

    /**
     * 根据广告位编号查询广告位预定信息
     *
     * @param id 广告位编号
     * @return 广告位预定信息
     */
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "广告位编号")})
    @GetMapping("/spot/reserve/{id}")
    public ResponseEntity<Result<SpotReserveVo>> getSpotReserveBySpotId(@PathVariable("id") Long id) {
        return new ResponseEntity(new Result().ok("success", spotService.getSpotReserveBySpotId(id)), HttpStatus.OK);
    }

    /**
     * 增加广告位
     *
     * @param spotVo 广告位
     * @return 操作状态
     */
    @PostMapping("/spot/add")
    public ResponseEntity<Result> addSpot(@RequestBody @ApiParam(name = "spotVo", value = "广告位") SpotVo spotVo) {
        spotService.addSpot(spotVo);
        return new ResponseEntity<>(new Result().ok("add success"), HttpStatus.OK);
    }

    /**
     * 更新广告位
     *
     * @param spotVo 广告位
     * @return 操作状态
     */
    @PutMapping("/spot/update")
    public ResponseEntity<Result> updateSpot(@RequestBody @ApiParam(name = "spotVo", value = "广告位") SpotVo spotVo) {
        spotService.updateSpot(spotVo);
        return new ResponseEntity<>(new Result().ok("update success"), HttpStatus.OK);
    }

    /**
     * 根据Id删除广告位
     *
     * @param id 广告位编号
     * @return 操作状态
     */
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "广告位编号")})
    @DeleteMapping("/spot/delete/{id}")
    public ResponseEntity<Result> deleteSpot(@PathVariable("id") Long id) {
        spotService.deleteSpot(id);
        return new ResponseEntity<>(new Result().ok("delete success"), HttpStatus.OK);
    }

    /**
     * 根据广告位Id查询最晚档期结束时间
     *
     * @param spotId 广告位Id
     * @return 最晚档期结束时间
     */
    @ApiImplicitParams({@ApiImplicitParam(name = "spotId", value = "广告位编号")})
    @GetMapping("/spot/latestReserveDate/{spotId}")
    public ResponseEntity<Result> getLatestDateBySpotId(@PathVariable("spotId") Long spotId) {
        return new ResponseEntity<>(new Result().ok("success", spotService.getLatestReserveDateBySpotId(spotId)), HttpStatus.OK);
    }
}
